@file:Suppress("UNCHECKED_CAST")

package com.hoow.shakoow.extend

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.hoow.shakoow.base.BaseActivity
import com.hoow.shakoow.enums.PageTagEnum
import com.hoow.shakoow.shake.*


inline fun <reified T> AppCompatActivity.startToNextActivity(params: HashMap<String, String> = HashMap()) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startToNextActivityAndFinish(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startToNextActivityForSingleTop(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

fun Fragment.startToNextFromPage(
    pageTag: PageTagEnum,
    params: HashMap<String, String> = HashMap()
) {
    (requireContext() as BaseActivity).startToNextFromPage(
        pageTag = pageTag,
        params = params
    )
}

fun AppCompatActivity.startToNextFromPage(
    pageTag: PageTagEnum,
    params: HashMap<String, String> = HashMap()
) {

}




//////////////////////////
/** 去摇一摇篮页 */
fun AppCompatActivity.startToShakePage(params: HashMap<String, String> = HashMap()) {
    startToNextActivityForSingleTop<ShakeActivity>(params)
}

/** 去我的资料页 */
fun AppCompatActivity.startToMyDetailPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserDetailSelfActivity>(params)
}

/** 去打招呼的人页 */
fun AppCompatActivity.startToGreetHistoryPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<GreetHistoryActivity>(params)
}

/** 去历史摇一摇页 */
fun AppCompatActivity.startToShakeHistoryPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<ShakeHistoryActivity>(params)
}

/** 去充值页 */
fun AppCompatActivity.startToUserRechargePage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserRechargeActivity>(params)
}

/** 去相册页 */
fun AppCompatActivity.startToUserAblumPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserAblumActivity>(params)
}

/** 去相册页 */
fun AppCompatActivity.startToUserAblumSelfPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserAblumSelfActivity>(params)
}

/** 去用户资料页 */
fun AppCompatActivity.startToUserDetailPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserDetailActivity>(params)
}

/** 去回复页 */
fun AppCompatActivity.startToReplyPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<ToReplyActivity>(params)
}

/** 去打招呼页 */
fun AppCompatActivity.startToGreetPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<ToGreetActivity>(params)
}

/** 去回复列表页 */
fun AppCompatActivity.startToUserChatInfoPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserChatInfoActivity>(params)
}

/** 去反馈页 */
fun AppCompatActivity.startToUserFeedbackPage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<UserFeedbackActivity>(params)
}

/** 去设置昵称页 */
fun AppCompatActivity.startToSetNickNamePage(params: HashMap<String, String> = HashMap()) {
    startToNextActivity<SetNickNameActivity>(params)
}

/** 去昵称页 */
fun Fragment.startToSetNickNamePage(params: HashMap<String, String> = HashMap()) {
    (requireContext() as BaseActivity).startToNextActivity<SetNickNameActivity>(
        params
    )
}